<!DOCTYPE HTML>
<html>
<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no"/>
    <meta http-equiv="Cache-Control" content="no-siteapp"/>
    <!--[if lt IE 9]>
    <script type="text/javascript" src="../../lib/html5shiv.js?rev=@@hash"></script>
    <script type="text/javascript" src="../../lib/respond.min.js?rev=@@hash"></script>
    <![endif]-->
    <link rel="stylesheet" type="text/css" href="../../static/h-ui/css/H-ui.min.css"/>
    <link rel="stylesheet" type="text/css" href="../../static/h-ui.admin/css/H-ui.admin.css"/>
    <link rel="stylesheet" type="text/css" href="../../lib/Hui-iconfont/1.0.8/iconfont.css"/>
    <link rel="stylesheet" type="text/css" href="../../static/h-ui.admin/skin/default/skin.css" id="skin"/>
    <link rel="stylesheet" type="text/css" href="../../static/h-ui.admin/css/style.css"/>
    <link rel="stylesheet" type="text/css" href="../../ht-css/Project.css"/>
    <link rel="stylesheet" type="text/css" href="../../lib/Validform/5.3.2/style.css"/>
    <!--[if IE 6]>
    <script type="text/javascript" src="../../lib/DD_belatedPNG_0.0.8a-min.js?rev=@@hash"></script>
    <script>DD_belatedPNG.fix('*');</script>
    <![endif]-->
    <link rel="stylesheet" type="text/css" href="../../ht-css/style-q.css"/>
    <title></title>
</head>

<body>
<form id="brandForm" enctype="multipart/form-data">
    <div class="cl clearfix pl-20 pt-15">
        <label class="form-label f-l text-r" style="width:90px;"><span class="c-red pr-5">*</span>品牌名称：</label>
        <div class="formControls f-l">
            <input type="text" class="input-text" value="" placeholder="" id="brandName" name=""
                   datatype="*0-20" errormsg="格式错误，请重新输入">
        </div>
        <span class="Validform_checktip"></span>
    </div>
    <div class="cl clearfix pl-20 pt-15">
        <label class="form-label f-l text-r" style="width:90px;"><span class="c-red pr-5">*</span>Logo：</label>
        <div class="formControls f-l"><img title="" width="50" height="50" src="" id="myImg" class="mr-10">
            <a onclick="addBtn()"><i class="Hui-iconfont f-22 mt-10"></i></a><input id="fileUp" type="file"
                                                                                     onchange="putDataToPage(event)"
                                                                                     style="display: none"></div>
    </div>
    <div class="cl clearfix pl-20 pt-15">
        <label class="form-label f-l text-r" style="width:90px;">简介：</label>
        <div class="formControls f-l">
            <textarea name="" class="textarea" maxlength="500" id="intro" placeholder=""
                      style="width:450px;"></textarea>
        </div>
    </div>
    <div class="text-c pd-20">
        <button type="submit" onclick="add_submit();" class="btn btn-primary radius">&nbsp;&nbsp;确认&nbsp;&nbsp;</button>
        <button onclick="addCancel();" class="btn radius ml-20" type="button">&nbsp;&nbsp;取消&nbsp;&nbsp;</button>
    </div>
</form>
</body>
<script type="text/javascript" src="../../lib/jquery/1.9.1/jquery.min.js?rev=@@hash"></script>
<script type="text/javascript" src="../../lib/layer/2.4/layer.js?rev=@@hash"></script>
<script type="text/javascript" src="../../static/h-ui/js/H-ui.min.js?rev=@@hash"></script>
<script type="text/javascript" src="../../static/h-ui.admin/js/H-ui.admin.js?rev=@@hash"></script>
<!--/_footer 作为公共模版分离出去-->
<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" src="../../lib/My97DatePicker/4.8/WdatePicker.js?rev=@@hash"></script>
<!--表单验证-->
<script type="text/javascript" src="../../lib/jquery.validation/1.14.0/jquery.validate.js?rev=@@hash"></script>
<script type="text/javascript" src="../../lib/jquery.validation/1.14.0/validate-methods.js?rev=@@hash"></script>
<script type="text/javascript" src="../../lib/jquery.validation/1.14.0/messages_zh.js?rev=@@hash"></script>
<script type="text/javascript" src="../../lib/datatables/1.10.0/jquery.dataTables.min.js?rev=@@hash"></script>
<script type="text/javascript" src="../../lib/laypage/1.2/laypage.js?rev=@@hash"></script>
<script type="text/javascript" src="../../lib/Validform/5.3.2/Validform_v5.3.2_min.js?rev=@@hash"></script>
<script src="../../ht-js/public.js?rev=@@hash"></script>
<!--验证token-->
<script src="../../ht-js/verifyToken.js?rev=@@hash"></script>
<script src="../../ht-js/Project.js?rev=@@hash"></script>
<script>
    function addBtn() {
        $("#fileUp").trigger('click');
    }

    var formData = new FormData();

    function putDataToPage(e) {
        //console.log($("#intro").val())
        for (var i = 0; i < e.target.files.length; i++) {
            var file = e.target.files.item(i);
            if (!(/^image\/.*$/i.test(file.type))) {
                continue; //不是图片 就跳出这一次循环
            }
            //实例化FileReader API
            var freader = new FileReader();
            freader.readAsDataURL(file);
            freader.onload = function (e) {
                $("#myImg").attr("src", e.target.result);
            }
        }
        formData.set('file', $("#fileUp")[0].files[0]);
    }

    //var canSure = true;
    //if(canSure == true) {
    var localStorageParameters = decodeURIComponent(web.readCookie("loginData"));
    var JsonObject =JSON.parse(localStorageParameters);
    var brandForm = $("#brandForm").Validform({
        tiptype: 2,
        callback: function (form) {
            canSure = false;
            formData.set("brandName", $("#brandName").val().replace(/[\r\n\s\t]/g,""));
            formData.set("description", $("#intro").val().replace(/[\r\n\s\t]/g,""));
            formData.set("creationBy",JsonObject.user.user_ID);
            $.ajax({
                url: root.goodsInter.goods_addBrand,
                // url:"http://192.168.65.110:7050/aproduct/brand/addBrand",
                cache: false, //禁用缓存
                type: "POST",
                // 告诉jQuery不要去处理发送的数据
                processData: false,
                // 告诉jQuery不要去设置Content-Type请求头
                contentType: false,
                data: formData,
                success: function (data) {
                    if (data.errorCode == 0) {
                        window.parent.brand_list(1, 50);
                        var index = parent.layer.getFrameIndex(window.name);
                        parent.layer.close(index);
                        showmsg("添加品牌成功", 6);
                    } else {
                        showmsg(data.errorMessage, 5);
                    }
                }
            });
            return false;
        }
    });
    //}
    // 提示信息
    function showmsg(msg, icon) {
        layer.msg(msg, {
            icon: icon,
            time: 1000
        }, function () {
            if (icon == 6) {
                // var index = parent.location.reload();
                // parent.layer.close(index);
                window.location.reload();
            }
        });
    }

    function addCancel() {
        layer.confirm('确定要取消吗?', function(index){
            layer.msg('已取消', {
                icon: 1,
                time: 1000 //2秒关闭（如果不配置，默认是3秒）
            }, function(){
                parent.layer.closeAll();
                layer.close(index);
            });

        });
    }

    // 添加品牌
    function add_submit() {
    }
</script>

</html>